﻿@{
    Layout = "~/Views/Shared/_FormGray.cshtml";
}

@inject Microsoft.AspNetCore.Hosting.IWebHostEnvironment HostingEnvironment
@section header{
    @BundlerHelper.Render(HostingEnvironment.ContentRootPath, Url.Content("~/lib/fileinput/5.0.3/css/fileinput.min.css"))
    @BundlerHelper.Render(HostingEnvironment.ContentRootPath, Url.Content("~/lib/fileinput/5.0.3/js/fileinput.min.js"))
}

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>文件上传控件 <small>https://github.com/kartik-v/bootstrap-fileinput</small></h5>
                </div>
                <div class="ibox-content">
                    @*<div class="form-group">
                        <label class="font-noraml">img</label>
                        <div class="file-loading">
                            <input type="file" name="img" id="img" value="" multiple="multiple" data-show-preview="true" />
                        </div>
                    </div>*@
                    <div class="form-group">
                        <label class="font-noraml">简单示例</label>
                        <div class="file-loading">
                            <input id="fileinput-demo-1" type="file">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="font-noraml">多文件上传</label>
                        <div class="file-loading">
                            <input id="fileinput-demo-2" type="file" multiple>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    $(document).ready(function () {
        $("#fileinput-demo-1").fileinput({
            language: 'zh',
            'uploadUrl': '@GlobalContext.SystemConfig.ApiSite' + '/File/UploadFile?fileModule=@UploadFileType.News.ParseToInt()',
            showPreview: false
        });

        $("#fileinput-demo-2").fileinput({
            language: 'zh',
            'uploadUrl': '@GlobalContext.SystemConfig.ApiSite' + '/File/UploadFile?fileModule=@UploadFileType.News.ParseToInt()',
            overwriteInitial: false,
            initialPreviewAsData: true,
            initialPreview: ['@Url.Content("~/image/portrait.png")']
        });

        $("#img").fileinput({
            language: 'zh',//设置文中文
            uploadUrl: '@GlobalContext.SystemConfig.ApiSite' + '/File/UploadFile?fileModule=@UploadFileType.News.ParseToInt()',
            showCaption: true,//显示标题
            showRemove: true, //显示移除按钮
            uploadAsync: true,//默认异步上传
            showPreview: true,//是否显示预览
            textEncoding: "UTF-8",//文本编码
            autoReplaceBoolean: false,//选择图片时不清空原图片
        });

        var list = []
        $("#fileinput-demo-2").on('fileuploaded', function (event, data, previewId, index) {//异步上传成功结果处理
           // var img = JSON.parse(data.response);//接收后台传过来的json数据
            
            list.push(data.response.Result);
            console.log(list)
        });

    });
</script>